package com.gthncz;

import jdk.nashorn.internal.runtime.regexp.joni.exception.ValueException;

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Demo14 {


    /*请完成下面这个函数，实现题目要求的功能
    当然，你也可以不按照下面这个模板来作答，完全按照自己的想法来 ^-^
    ******************************开始写代码******************************/
    static String reverse(String sourceStr, String changeStr) {
        char[] pattern = changeStr.toCharArray();
        int i=0, j=pattern.length-1;

        char tmp;
        while (i<j) {
            tmp = pattern[i];
            pattern[i] = pattern[j];
            pattern[j] = tmp;
            ++i; --j;
        }

        StringBuilder builder = new StringBuilder();
        int sourceLength = sourceStr.length();
        int pos = 0, next=0;

        while (pos < sourceLength) {
            next = sourceStr.indexOf(changeStr, pos);
            if (next == -1) {
                builder.append(sourceStr.substring(pos));
                break;
            } else if (next < sourceLength) {
                builder.append(sourceStr, pos, next);
                builder.append(pattern);
                pos = next + pattern.length;
            } else {
                throw new ValueException("unexpect pos: " + pos);
            }
        }
        return builder.toString();
    }
    /******************************结束写代码******************************/


    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String res;

        String _sourceStr;
        try {
            _sourceStr = in.nextLine();
        } catch (Exception e) {
            _sourceStr = null;
        }

        String _changeStr;
        try {
            _changeStr = in.nextLine();
        } catch (Exception e) {
            _changeStr = null;
        }

        res = reverse(_sourceStr, _changeStr);
        System.out.println(res);
    }
}
